const axios = require("axios");
const cheerio = require("cheerio");

// 获取steam排行榜
async function getYouxiaSteamRanking() {
  const res = await axios.get("https://0day.ali213.net/");
  return parseSteamRanking(res.data, "https://0day.ali213.net/");
}

function parseSteamRanking(page, baseUrl) {
  const $ = cheerio.load(page);
  let steamList = [];
  $(".s2-right-tbody a").each(function () {
    const item = {};
    item.index = $(".s2-right-td1", this).text();
    item.link = `${baseUrl}${$(this).attr("href")}`;
    item.name = $(".s2-right-td2", this).text();
    item.count = $(".s2-right-td3", this).text();
    steamList.push(item);
  });
  return steamList;
}

module.exports = getYouxiaSteamRanking;
